/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import BD.Retenciones;
import Seniat.Seniat;
import Seniat.Utils;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.io.File;
import java.util.List;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.TableColumn;

/**
 *
 * @author ARMGARCES
 */
public class VentanaBusqueda extends javax.swing.JFrame {
    private File file;
    private static Ventana ventana;
    private static JTable table;
    private String mensj;
    private int ancho  = 935;
    private int alto   = 525;
    /**
     * Creates new form VentanaArchivo
     * @param vent 
     */
    public VentanaBusqueda(Ventana vent) {
        initComponents();
        this.setTitle("Busqueda de Documentos");
        mensj = "";
        ventana = vent;
        l_num.setText("");
        l_rif.setText("");
        l_tipo.setText("");
        l_periodo.setText("");
        l_agente.setText("");
    }

    /**
     * 
     */
    public void centrarVentana(){
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Dimension screenSize = toolkit.getScreenSize();
        this.setSize(ancho,alto);

        int x = (screenSize.width  -  this.getWidth()) / 2;
        int y = (screenSize.height - this.getHeight()) / 2;
        this.setLocation(x, y);
        
        this.setResizable(false);
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        l_mes = new javax.swing.JLabel();
        l_archivo = new javax.swing.JLabel();
        c_mes = new javax.swing.JComboBox();
        l_ano = new javax.swing.JLabel();
        c_ano = new javax.swing.JComboBox();
        l_busqueda = new javax.swing.JLabel();
        c_tipo = new javax.swing.JComboBox();
        l_param = new javax.swing.JLabel();
        t_rif = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        l_param1 = new javax.swing.JLabel();
        l_periodo = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        l_tipo = new javax.swing.JLabel();
        l_mes1 = new javax.swing.JLabel();
        l_rif = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        l_agente = new javax.swing.JLabel();
        p_tabla = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        l_num = new javax.swing.JLabel();
        b_buscar = new javax.swing.JButton();
        Regresar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setPreferredSize(new java.awt.Dimension(715, 500));
        setResizable(false);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), "Seniat"));
        jPanel1.setMaximumSize(new java.awt.Dimension(925, 497));
        jPanel1.setMinimumSize(new java.awt.Dimension(925, 497));
        jPanel1.setPreferredSize(new java.awt.Dimension(925, 497));

        l_mes.setText("Seleccione el periodo de Busqueda:");

        c_mes.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" }));

        l_ano.setText("Seleccione el año de Busqueda:");

        c_ano.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "2013", "2012", "2011", "2010", "2009", "2008", "2007", "2006", "2005", "2004" }));

        l_busqueda.setText("Seleccionar tipo de Busqueda:");

        c_tipo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "por RIF", "por FACTURA", "por NRO.CONTROL", "por DOC.AFECTADO", "por MONTO" }));
        c_tipo.setMaximumSize(null);
        c_tipo.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                c_tipoItemStateChanged(evt);
            }
        });

        l_param.setText("Introduzca el rif a Consultar:");

        t_rif.setMaximumSize(null);
        t_rif.setMinimumSize(null);
        t_rif.setPreferredSize(null);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), "Resultados"));
        jPanel2.setMaximumSize(null);
        jPanel2.setMinimumSize(new java.awt.Dimension(900, 550));
        jPanel2.setPreferredSize(new java.awt.Dimension(910, 305));

        l_param1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        l_param1.setText("Rif:");

        l_periodo.setText("Mes 2013");

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel7.setText("Tipo Busqueda:");

        l_tipo.setText("Certificaciones");

        l_mes1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        l_mes1.setText("Periodo:");

        l_rif.setText("J401087000");

        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel11.setText("Razon Social:");

        l_agente.setText("Pedro Perez c.a");

        p_tabla.setMaximumSize(null);
        p_tabla.setPreferredSize(new java.awt.Dimension(870, 200));
        p_tabla.setRequestFocusEnabled(false);

        javax.swing.GroupLayout p_tablaLayout = new javax.swing.GroupLayout(p_tabla);
        p_tabla.setLayout(p_tablaLayout);
        p_tablaLayout.setHorizontalGroup(
            p_tablaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 870, Short.MAX_VALUE)
        );
        p_tablaLayout.setVerticalGroup(
            p_tablaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 200, Short.MAX_VALUE)
        );

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel6.setText("Num. Registros:");

        l_num.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        l_num.setText("129");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(p_tabla, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(l_num, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(70, 70, 70)
                                .addComponent(jLabel7)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(l_tipo))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel11)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(l_agente, javax.swing.GroupLayout.PREFERRED_SIZE, 341, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(43, 43, 43)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(l_param1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(l_rif))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(l_mes1)
                                .addGap(18, 18, 18)
                                .addComponent(l_periodo)))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(l_periodo)
                    .addComponent(jLabel7)
                    .addComponent(l_tipo)
                    .addComponent(l_mes1)
                    .addComponent(jLabel6)
                    .addComponent(l_num))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(l_param1)
                        .addComponent(l_rif))
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel11)
                        .addComponent(l_agente)))
                .addGap(18, 18, 18)
                .addComponent(p_tabla, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        b_buscar.setText("Buscar");
        b_buscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_buscarActionPerformed(evt);
            }
        });

        Regresar.setText("Regresar");
        Regresar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RegresarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 900, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(l_archivo)
                .addGap(87, 87, 87))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(Regresar, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(103, 103, 103))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(l_mes, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(l_ano, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(28, 28, 28)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(c_mes, 0, 100, Short.MAX_VALUE)
                    .addComponent(c_ano, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(l_busqueda)
                    .addComponent(l_param))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(t_rif, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(c_tipo, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(b_buscar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(95, 95, 95))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(l_busqueda)
                            .addComponent(c_tipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(l_param)
                            .addComponent(t_rif, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(b_buscar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(Regresar)
                        .addContainerGap(32, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(l_mes)
                            .addComponent(c_mes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(l_ano)
                            .addComponent(c_ano, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 65, Short.MAX_VALUE)
                        .addComponent(l_archivo)
                        .addGap(346, 346, 346))))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void b_buscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_buscarActionPerformed
        // TODO add your handling code here:
        //
        int mes = c_mes.getSelectedIndex()+1;
        int ano = Integer.parseInt((String)c_ano.getSelectedItem());
        int tipo = c_tipo.getSelectedIndex();
        String param  = t_rif.getText();
        
        l_periodo.setText(Utils.getPeriodo(tipo, mes, ano));
        l_tipo.setText(Utils.getTipo(tipo));
        l_rif.setText(param);
        l_num.setText("0");        
        List<Retenciones> list = null;
        list = Seniat.getInstance().buscar(tipo,param, mes, ano);
        printTable(list);
        
        if(list.size() > 0){
            l_num.setText(""+list.size());
            Retenciones retencion = list.get(0);
            l_agente.setText(retencion.getAgente());
        }
            
    }//GEN-LAST:event_b_buscarActionPerformed
    /**
     * 
     * @param evt 
     */
    private void RegresarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RegresarActionPerformed
        // TODO add your handling code here:
        //
        ventana.setVisible(true);
        this.dispose();
    }//GEN-LAST:event_RegresarActionPerformed
    /**
     * 
     * @param evt 
     */
    private void c_tipoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_c_tipoItemStateChanged
        // TODO add your handling code here:
        //
        l_mes.setText("");
        l_ano.setText("");
                             
        switch(c_tipo.getSelectedIndex()){
            //etiquetas y campos para la busqueda por rif y periodo
            case 0:
                l_mes.setText("Seleccione el periodo de Busqueda:");
                l_ano.setText("Seleccione el año de Busqueda:");
                l_param.setText("Introduzca el rif a Consultar:");
                l_mes1.setText(Utils.getLabelMes(c_tipo.getSelectedIndex()));
                l_param1.setText(Utils.getParam(c_tipo.getSelectedIndex()));
                jLabel11.setVisible(true);
                l_agente.setVisible(true);
                c_mes.setVisible(true);
                c_ano.setVisible(true);                
                
                break;
            //etiquetas y campos para la busqueda por factura 
            case 1:
                l_param.setText("Introduzca el nro. de Factura:");
                l_mes1.setText(Utils.getLabelMes(c_tipo.getSelectedIndex()));
                l_param1.setText(Utils.getParam(c_tipo.getSelectedIndex()));
                jLabel11.setVisible(true);
                l_agente.setVisible(true);
                c_mes.setVisible(false);
                c_ano.setVisible(false);                 
                break;
            //etiquetas y campos para la busqueda por nro de control
            case 2:
                l_param.setText("Introduzca el nro. de Control:");
                l_mes1.setText(Utils.getLabelMes(c_tipo.getSelectedIndex()));
                l_param1.setText(Utils.getParam(c_tipo.getSelectedIndex()));
                jLabel11.setVisible(true);
                l_agente.setVisible(true);
                c_mes.setVisible(false);
                c_ano.setVisible(false);
                break;
            //etiquetas y campos para la busqueda por nro. de factura afectada
            case 3:
                l_param.setText("Introduzca el nro. de Factura Afectada:");
                l_mes1.setText(Utils.getLabelMes(c_tipo.getSelectedIndex()));
                l_param1.setText(Utils.getParam(c_tipo.getSelectedIndex()));
                jLabel11.setVisible(true);
                l_agente.setVisible(true);
                c_mes.setVisible(false);
                c_ano.setVisible(false);
                break;
            //etiquetas y campos para la busqueda por nro. de factura afectada
            case 4:
                l_param.setText("Introduzca el Monto de la Factura:");
                l_mes1.setText(Utils.getLabelMes(c_tipo.getSelectedIndex()));
                l_param1.setText(Utils.getParam(c_tipo.getSelectedIndex()));
                jLabel11.setVisible(false);
                l_agente.setVisible(false);
                c_mes.setVisible(false);
                c_ano.setVisible(false);
                break;
        }
    }//GEN-LAST:event_c_tipoItemStateChanged

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Regresar;
    private javax.swing.JButton b_buscar;
    private javax.swing.JComboBox c_ano;
    private javax.swing.JComboBox c_mes;
    private javax.swing.JComboBox c_tipo;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JLabel l_agente;
    private javax.swing.JLabel l_ano;
    private javax.swing.JLabel l_archivo;
    private javax.swing.JLabel l_busqueda;
    private javax.swing.JLabel l_mes;
    private javax.swing.JLabel l_mes1;
    private javax.swing.JLabel l_num;
    private javax.swing.JLabel l_param;
    private javax.swing.JLabel l_param1;
    private javax.swing.JLabel l_periodo;
    private javax.swing.JLabel l_rif;
    private javax.swing.JLabel l_tipo;
    private javax.swing.JPanel p_tabla;
    private javax.swing.JTextField t_rif;
    // End of variables declaration//GEN-END:variables

    /**
     * 
     * @param _file 
     */
    protected void updateFile(File _file) {
        file = _file;
        
        if(file != null){
            mensj = file.getName();
        }else{
            mensj = "";
        }
    }

    /**
     * 
     * @param list 
     */
    private void printTable(List<Retenciones> list){
        String[] columnNames = {"FECHA",
                                "TIPO",
                                "NRO.DOCUMENTO",
                                "NRO.CONTROL",
                                "NRO.AFECTADO",
                                "MONTO",
                                "RETENIDO",
                                "EXCENTO",
                                "ALICUOTA"};
 
        Object[][] data = new Object[list.size()][9];
        int size = 0;
        size = list.size();
        table = null;
        
        for (int i = 0; i < size; i++) {
            Retenciones retencion = list.get(i);
            
            data[i][0] = Utils.formatDate(retencion.getFecha());
            data[i][1] = retencion.getDocumento();
            data[i][2] = retencion.getNroDocumento().substring(0, retencion.getNroDocumento().length()-2);
            data[i][3] = retencion.getNroControl();
            data[i][4] = retencion.getNroAfectado().substring(0, retencion.getNroAfectado().length()-2);
            data[i][5] = ""+retencion.getMonto1();
            data[i][6] = ""+retencion.getRetenido1();
            data[i][7] = ""+retencion.getExcento1();
            data[i][8] = ""+retencion.getAlicuota();
        }
        p_tabla.removeAll();
        
        table = new JTable(data, columnNames);
        table.setPreferredScrollableViewportSize(new Dimension(650, 170));
  
        TableColumn column = null;
        for (int i = 0; i < table.getColumnCount(); i++) {            
            column = table.getColumnModel().getColumn(i);
            if (i==1 || i == 2 || i==3) {
                column.setPreferredWidth(125); //third column is bigger
            }
            if (i==0 ) {
                column.setPreferredWidth(100); //third column is bigger
            }
        }
        //Create the scroll pane and add the table to it.
        p_tabla.setLayout(new BorderLayout());
        JScrollPane tableContainer = new JScrollPane(table);
        p_tabla.add(tableContainer, BorderLayout.CENTER);
        
        repaint();
    }
    
}
